package com.atguigu.gmall.order.config;

import com.atguigu.gmall.common.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author atguigu-mqx
 */
@Configuration
public class OrderDelayedConfig {

    //  定义交换机
    @Bean
    public CustomExchange delayOrderExchange(){
        //  设置参数
        HashMap<String, Object> map = new HashMap<>();
        map.put("x-delayed-type","direct");
        //  第二个参数固定值！
        return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL,"x-delayed-message",true,false,map);
    }
    //  定义队列
    @Bean
    public Queue delayOrderQueue(){
        //  返回队列
        return new Queue(MqConst.QUEUE_ORDER_CANCEL,true,false,false);
    }
    //  定义绑定关系
    @Bean
    public Binding delayOrderBinding(){
        //  返回绑定关系！
        return BindingBuilder.bind(delayOrderQueue()).to(delayOrderExchange()).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }
}
